package com.example.springmvc.controller;

import com.example.springmvc.entity.UserEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.util.UUID;


@RestController
public class UserController {
    @RequestMapping("/sayHi")
    public Object sayHi(UserEntity user) {
        return user;
    }
}

//    private static final String SESSION_KEY = "USER_SESSION_KEY";
//
//    @RequestMapping("/setSession")
//    public Object setSession(HttpServletRequest request) {
//        HttpSession session = request.getSession();
//        session.setAttribute(SESSION_KEY, "xiaoyang");
//        return "Session 存储成功 ！";
//    }
//
//    @RequestMapping("/getSession")
//    public Object getSession(@SessionAttribute(SESSION_KEY) String Session) {
//        return "SSESSION_KEY = " + Session;
//    }
//}

//    @RequestMapping("/getCookie")
//    public Object getCookie(@CookieValue("testCookie") String testCookie) {
//        return "Cookie: " + testCookie;
//    }
//}

//    @RequestMapping("/upload")
//    public Object upLoad(@RequestPart("Img") MultipartFile file) {
//        String fileName = UUID.randomUUID() +
//                file.getOriginalFilename().substring(
//                        file.getOriginalFilename().lastIndexOf("."));
//        File saveFile = new File("D:\\Image\\"+fileName);
//        try {
//            file.transferTo(saveFile);
//            return "上传图片成功！";
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return "上传图片失败！";
//    }
//}
//
